package com.bnq.logc.upload

import com.bnq.logc.LogcManager
import com.bnq.logc.config.LogcConfig
import com.google.gson.Gson
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Response
import java.io.IOException

object SendApiManager {

    private val mSendApiClient by lazy { when(LogcManager.getConfig().mFileUploadServer){
        LogcConfig.FileUploadServer.UC -> UcSendApiClient()
        LogcConfig.FileUploadServer.COS -> CosSendApiClient()
    } }

    fun sendLog(url:String,map: Map<String,Any?>){
        mSendApiClient.post(url,null, Gson().toJson(map),object : Callback {

            override fun onFailure(call: Call, e: IOException) {
                e.printStackTrace()
            }

            override fun onResponse(call: Call, response: Response) {

            }

        })
    }

}

interface SendApiClient{
    fun post(url:String,headers:Map<String,String>?,body:String,callback: Callback)
}

class UcSendApiClient : SendApiClient{
    override fun post(
        url: String,
        headers: Map<String, String>?,
        body: String,
        callback: Callback
    ) {
        UfileClientManager.post(url,null, body,callback)
    }

}

class CosSendApiClient : SendApiClient{
    override fun post(
        url: String,
        headers: Map<String, String>?,
        body: String,
        callback: Callback
    ) {
        CosFileClientManager.post(url,null, body,callback)
    }

}